package 接口.练习;
//拷贝
class Address implements Cloneable{
    int size;

    public Address(int size) {
        this.size = size;
    }

    @Override
    protected Object clone() throws CloneNotSupportedException {
        return super.clone();
    }

    @Override
    public String toString() {
        return "Address{" +
                "size=" + size +
                '}';
    }
}
class School implements Cloneable{
    int price;
    Address address;

    public School(int price, Address address) {
        this.price = price;
        this.address = address;
    }

    @Override
    public String toString() {
        return "School{" +
                "price=" + price +
                ", address=" + address +
                '}';
    }

    @Override
    protected Object clone() throws CloneNotSupportedException {
        School stm = (School) super.clone();
        stm.address = (Address) this.address.clone();
        return stm;
    }

}
public class Clone_Text_2 {
    public static void main(String[] args) throws CloneNotSupportedException {
        Address address =new Address(1000);
        School school1 = new School(800,address);
        School school2 = (School) school1.clone();
        System.out.println("拷贝后");
        System.out.println(school1);
        System.out.println(school2);
        System.out.println("进行修改");
        school1.address.size = 15000;
        System.out.println(school1);
        System.out.println(school2);
    }
}
